<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<%@ include file="/pub/head_bootstrap.inc"%>
<title>${module.moduleName}</title>
</head>
<body>
	<!-- 表格列表 -->
	<body class="FrameRightBg">
	<div class="FrameRight" id="FrameRightContent">
		<div class="FrameRightInner mlzjhzdlb-default">
			
			<!-- location --> 
			<div class="main">
				<div id="standardSearchForm">
					<%@ include file="../selector_form.jsp"%>
					<form id="formsearch" method="post">
						<input type="hidden" name="${module.module}list" id="${module.module}list"
							class="field" />
						<div class="selector-form"></div>
					</form>
				</div>
 
				<div class="common-option">
					<div class="inner">
						<button type="button"  class="btn btn-icon" onclick="StandardTable.add()"><i class="a fa fa-plus-square-o"></i>新增</button>
						<button type="button"  class="btn btn-icon" onclick="StandardTable.edit()"><i class="a fa fa-pencil-square-o"></i>修改</button>
						<button type="button"  class="btn btn-icon" onclick="StandardTable.deleteByIds()"><i class="a fa fa-minus-square-o"></i>删除</button>
						<button type="button"  class="btn btn-icon" onclick="StandardTable.init()"><i class="icon iconfont icon-icon-dowmload"></i>同步模型接口</button>
					</div> 
				</div> <!--common-option -->
	
				<div class="common-table">
					<table id="standardTable" class="table table-hover"></table>
				</div>
			</div>
			<!-- main end -->
		</div>
		<!-- FrameRightInner -->
	</div>
	<!-- FrameRight -->
	<%@ include file="interfacedetailedit_edit.jsp" %>
	<script>
	var win = parent || window;
 	 var selectorData = JSON.parse('${module.selectorData}'||"[]");
 	 if(selectorData.length > 0){
 		sortArr(selectorData, 'sort');
 		initData($(".selector-form"),selectorData,[],'${module.module}');	
		var searchCondition = JSON.parse('${module.searchCondition}'||"[]");
		for (var i = 0; i < searchCondition.length; i++) {
			var each = searchCondition[i];
			setSearchContainer(each.id, each.name, each.data);
		}
	  	//渲染选择器
	  	renderSelector(getDefaultSelector());
 	 }else{
 		 $("#standardSearchForm").hide();
 	 }
 	 
 	//生成列表
	var columns = genColumns('${module.moduleDisplay}');
	function genColumns(data){
  	 if(data){
  		 data = JSON.parse(data);
  		 var columns = new Array();
  		 
  		columns.push({
            field: 'checkbox',
	           checkbox: true
       });
       
       columns.push({
           field: 'number',
           title: '序号',
           formatter: function (value, row, index) {
               return (index+1);  
           }
       }); 
      	 for(var key in data){
      		 if(!data[key].isHidden){
      			 if (data[key].type == 'attach') {
      				columns.push({title:data[key].display,field:data[key].name,align:"center",
      					formatter: function (value, row, index) {
      						if (value) {
      							return '<a class="attach-download" attach-id="'+ row.ATTACH_ID +'">'+ value +'</a>'
      						}
      					}
      				});
      			 } else {
	       			 columns.push({title:data[key].display,field:data[key].name, type:data[key].type,align:"center" });
      			 }
      		 }
      	 }
    	columns.push({
            field: 'operation',
            title: '查看权限',
            formatter: function (value, row, index) {
            	var operation = [];
            	operation.push('<a class="submit-record" href="javascript:void(0);" onclick="openPersion(&apos;'+ row.id +'&apos;)" >查看</a>');
            	return operation.join('');
            }
        }); 
      	
      	 return columns;
  	 }
  	 return null;
   }
	
	StandardTable = {
		initTable: function(){
			$('#standardTable').bootstrapTable({
	       		url: "${baseURL}/jdbc/common/basecommonlist/listJSON.do?mdId=${param.mdId}",
	       		method: 'post',
	       		sidePagination: "server",
	       		dataType:'json',
	       		dataField: 'Rows',
	       		totalField: 'Total',
	       		contentType:'application/x-www-form-urlencoded',
	       		queryParamsType:"undefined",
	       		queryParams: StandardTable.queryParams,
	            striped: true,                      //是否显示行间隔色
	            pagination: true,
	            pageNumber:1,                       //初始化加载第一页，默认第一页
               pageSize: 15,                       //每页的记录行数（*）
               pageList: [15, 25, 50, 100],        //可供选择的每页的行数（*）
   	        	clickToSelect: true,                //是否启用点击选中行
	            uniqueId: "batchNum",                 //每一行的唯一标识，一般为主键列
	       		columns:  columns
			})
		}, 
		//查询参数
		queryParams: function(params){
			return {
				pageNo: params.pageNumber,
				perPageSize: params.pageSize,
				searchParam: JSON.stringify(getSelectorValue())
			}
		},
		
		/* 跳转详情页 */
		goDetailPage: function(){
			WinPrint2("${baseURL}/jdbc/common/basecommonedit/edit.do?mdId=${param.mdId}&menuId=${param.menuId}&random="+Math.random());
		},
		  
		//修改
		modifyDetailPage: function(){
			var selection = $("#standardTable").bootstrapTable('getSelections');
			if(selection.length==1){
				var row = selection[0];
				WinPrint2("${baseURL}/jdbc/common/basecommonedit/edit.do?mdId=${param.mdId}&menuId=${param.menuId}&id="+row.id+"&"+Math.random());
			}else{
				BT.showWarning("请至少选中一行！"); 
			}
		},
		//删除
		deleteByIds: function(){
			var selections = $("#standardTable").bootstrapTable('getSelections');
			if(selections.length>0){
				BT.showConfirm("删除","你确定删除所选信息吗？",function(){
					var ids = "";
					for(var i=0; i<selections.length; i++){
						ids = ids + selections[i].id + ",";
					}
					ids = ids.substring(0,ids.length-1);
					$.ajax({
						type: "POST",
						url:"${baseURL}/intermanage/interfacedetail/interfacedetaildelete/delete.do",
						dataType:'json',
						data:{ids:ids},
						success:function(data){
							if(data && data.hasOk == true){
								BT.showSuccess("删除成功!",function(){
									$("#standardTable").bootstrapTable("refresh");
								});
							}else{
								BT.showError("操作出错!"+data.message);
							}
						}
					})
				}) 
			}else{
				BT.showWarning("请至少选中一行！"); 
			}
		},
		edit: function(){
			var selection = $("#standardTable").bootstrapTable('getSelections');
			var row = selection[0];
			FF_ShowDialog(row);
			$('#editModal').modal();
		},
		add: function(){
 			FF_ShowDialog(null);
			$('#editModal').modal();
		},
		init: function(){
			loader.open(document.body);
			$.ajax({
				type: "POST",
				url:"${baseURL}/intermanage/interfacedetail/interfacedetaillist/init.do",
				dataType:'json',
				success:function(data){
					if(data && data.hasOk == true){
						loader.close(document.body);
						BT.showSuccess("同步模型接口成功!",function(){
							$("#standardTable").bootstrapTable("refresh");
						});
					}else{
						loader.close(document.body);
						BT.showError("操作出错!"+data.message);
					}
				}
			})
		},
		main: function(){
			var _this = StandardTable;
			_this.initTable();
			initSearchGrid($('#standardTable'));
		}
	}
	
	$(function () {
		StandardTable.main();

	/* 	var menuPathFullName = '${menuPathFullName }';
		if (menuPathFullName) {
			var nameArr = menuPathFullName.split('-');
			var location = [];
			for (var i = 1; i < nameArr.length; i++) {
				location.push('<a href="javascript:void(0);">' + nameArr[i] + '</a>');
				location.push((i < nameArr.length - 1 ? '<span>&gt;</span>' : ''));
			}
			$('.location .inner').append(location.join(''));
		} */
		
	});
	
	function sortArr(arr, prop) {
		if (arr && typeof arr.length != 'undefined'
			&& arr.length > 0 && prop) {
			arr.sort(function(elem1, elem2){
				vaildPriority(prop, elem1, elem2);
				return elem1[prop] - elem2[prop];
			});
		}
		function vaildPriority() {
			if (arguments.length < 2) {
				return;
			}
			var prop = arguments[0];
			for (var i = 1; i < arguments.length; i++) {
				if (!arguments[i]) {
					continue;
				}
				if (typeof arguments[i][prop] == 'undefined' 
						|| arguments[i][prop] == '' 
						|| isNaN(arguments[i][prop])) {
					arguments[i][prop] = 10000000;
				}
			}
		}
	}
	
	function openPersion(obj){
		window.location.href="${baseURL}/intermanage/interfacepermission/interfacepermissionlist/listByInterfaceId.do?id="+obj;
	}
	
	</script>
	
</body>
</html>
